package com.java.controller;

import com.java.entity.PageBean;
import com.java.entity.PsInspectiontaskDetail;
import com.java.entity.RespBean;
import com.java.service.PsInspectiontaskDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author caiyuan
 * @version 1.0
 * @Date 2020/6/25 4:10 Dream-Seeker
 * @Description
 */
@RestController
@RequestMapping("/inspectaskdetail")
@Scope("prototype")
public class PsInspectiontaskDetailController {
    @Autowired
    PsInspectiontaskDetailService psInspectiontaskDetailService;

    @GetMapping("/allInspectiontaskDetail")
    public RespBean allInspectiontaskDetail(@RequestParam(value = "currentPage", defaultValue = "1", required = false) Integer currentPage,
                                            @RequestParam(name = "inspectionTaskCode") String inspectionTaskCode,
                                            @RequestParam(name = "lineCode") String lineCode,
                                            @RequestParam(name = "bugTypeName") String bugTypeName,
                                            @RequestParam(name = "bugLevelName") String bugLevelName,
                                            @RequestParam(name = "Findthetimestart") String Findthetimestart,
                                            @RequestParam(name = "Findthetimeend") String Findthetimeend,
                                            @RequestParam(name = "issuedTimestart") String issuedTimestart,
                                            @RequestParam(name = "issuedTimeend") String issuedTimeend) {
        try {
            bugTypeName = new String(bugTypeName.getBytes("ISO-8859-1"), "UTF-8");
            bugLevelName = new String(bugLevelName.getBytes("ISO-8859-1"), "UTF-8");

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        PageBean<PsInspectiontaskDetail> list = psInspectiontaskDetailService.findByPageInspecDetail(currentPage,
                lineCode,bugTypeName,bugLevelName,Findthetimestart,Findthetimeend,issuedTimestart,issuedTimeend);
        if (list != null) {
            return RespBean.ok("查询成功", list);
        } else {
            return RespBean.error("查询失败");
        }

    } @GetMapping("/{lineCode}")
    public RespBean getInspecdetailBylineCodes(@PathVariable String lineCode) {
        List<PsInspectiontaskDetail> list = psInspectiontaskDetailService.getInspecdetailBylineCodes(lineCode);
        if (list != null) {
            return RespBean.ok("查询成功", list);
        } else {
            return RespBean.error("查询失败");
        }

    }


    @GetMapping("/getInspecBytaskId/{taskId}")
    public RespBean getInspecBytaskId(@PathVariable Integer taskId) {
        PsInspectiontaskDetail list = psInspectiontaskDetailService.getInspecdetailBytaskId(taskId);
        if (list != null) {
            return RespBean.ok("查询成功", list);
        } else {
            return RespBean.error("查询失败");
        }

    }

    @GetMapping("/getInspecBypoleCode/{poleCode}")
    public RespBean getInspecBypoleCode(@PathVariable String poleCode) {
        PsInspectiontaskDetail psInspectiontaskDetail = psInspectiontaskDetailService.getInspecBypoleCode(poleCode);
        if (psInspectiontaskDetail != null) {
            return RespBean.ok("查询成功", psInspectiontaskDetail);
        } else {
            return RespBean.error("查询失败");
        }

    }

    @PutMapping("/")
    public RespBean updatePsInspec(@RequestBody PsInspectiontaskDetail psInspectiontaskDetail) {
        Integer i = psInspectiontaskDetailService.updatePsInspec(psInspectiontaskDetail);
        if (i == 1) {
            return RespBean.ok("修改成功", i);
        } else {
            return RespBean.error("修改失败", i);
        }
    }


    @PostMapping("/")
    public RespBean addPsInspec(@RequestBody PsInspectiontaskDetail psInspectiontaskMain) {

        Integer i = psInspectiontaskDetailService.addPsInspectiontaskDetail(psInspectiontaskMain);
        if (i == 1) {
            return RespBean.ok("添加成功", i);
        } else {
            return RespBean.error("添加失败", i);
        }
    }


}
